package com.jg.dao.impl;

import com.jg.dao.BaseDao;
import com.jg.dao.DepartmentDao;
import com.jg.entity.Department;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 86130
 * @version 1.0
 * @description: TODO
 * @date 2025/3/27 10:31
 */
public class DepartmentDaoImpl extends BaseDao implements DepartmentDao {
    @Override
    public List<Department> getAllDepartments() {
        List<Department> list = new ArrayList<>();
        String sql = "SELECT * FROM department";
        ResultSet rs = executeQuery(sql);
        if (rs != null) {
            try {
                while (rs.next()) {
                    Department department = new Department();
                    department.setId(rs.getInt("id"));
                    department.setName(rs.getString("name"));
                    department.setDescription(rs.getString("description"));
                    list.add(department);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                closedAll(rs);
            }
        }
        return list;
    }
}
